package 力扣;

/**
 * @author ZhuYi
 * @create 2024/7/24 8:42
 */
public class 跳跃游戏2_45 {
    public static void main(String[] args) {
        int[] nums = {2, 3, 1, 1, 4};
        System.out.println(jump(nums));

    }

    public static int jump(int[] nums) {
        int n = nums.length - 1;
        int times = 0;
        while (n > 0) {
            for (int i = 0; i < n; i++) {
                if (nums[i] + i >= n) {
                    n = i;
                    times++;
                    break;
                }
            }
        }

        return times;
    }
}
